package com.mzj.saas.jobs.EnterpriseData.repository;

import com.mzj.saas.jobs.EnterpriseData.entity.DepartmentHierarchy;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface DepartmentHierarchyRepository extends JpaRepository<DepartmentHierarchy,Long>, JpaSpecificationExecutor<DepartmentHierarchy> {

    DepartmentHierarchy findByTagIdAndAreaId(Long tagId, Long areaId);

    List<DepartmentHierarchy> findByIdIn(List<Long> ids);

    boolean existsByParentId(Long id);

    @Query(nativeQuery=true,value = "SELECT MAX(id) FROM `saas_department_hierarchy` WHERE parent_id = :parentId")
    Long findByParentIdMaxId(@Param("parentId") Long parentId);

}
